<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline" style="text-align: left">
      <el-form-item label="所在区域">
        <el-select v-model="formInline.localArea" placeholder="请选择所在区域">
          <el-option label="请选择" value=""></el-option>
          <el-option label="操场" value="操场"></el-option>
          <el-option label="广场" value="广场"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="连接状态">
        <el-select
          v-model="formInline.connectionStatus"
          placeholder="请选择连接状态"
        >
          <el-option label="请选择" value=""></el-option>
          <el-option label="在线" value="true"></el-option>
          <el-option label="离线" value="false"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="load">查询</el-button>&nbsp;

        <el-button @click="tianjia">新增</el-button>
      </el-form-item>
    </el-form>
    <br />
    <template>
      <el-table
        border
        :row-class-name="tableRowClassName"
        :cell-style="rowStyle"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="equipmentNum" label="设备编号" width="120" align="center">
        </el-table-column>
        <el-table-column prop="lightPostNum" label="灯杆编号" width="120" align="center">
        </el-table-column>
        <el-table-column
          prop="localArea"
          label="所在区域"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column label="连接状态" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.connectionStatus == true">在线</span>
            <span v-else>离线</span>
          </template>
        </el-table-column>
        <el-table-column prop="openingTime" label="播放时间" width="120" align="center">
        </el-table-column>
        <el-table-column prop="closingTime" label="关闭时间" width="120" align="center">
        </el-table-column>
        <el-table-column prop="remark" label="操作" align="center">
          <template slot-scope="scope">
            <el-link type="success" @click="qidong(scope.row)">播放</el-link>
            <el-link type="warning" @click="guanbi(scope.row)">关闭</el-link>
            <el-link type="warning" @click="fantian(scope.row.id)"
              >修改</el-link
            >
            <el-link type="info" @click="shanchu(scope.row.id)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[2, 4, 6, 8]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>
  </div>
</template>
<script>
import { ShowLargeScreen } from "@/api/iotInfo/IargeScreen";
import { GetTotaocount } from "@/api/iotInfo/IargeScreen";
import { deleteLargeScreen } from "@/api/iotInfo/IargeScreen";
import { StationLargeScreen } from "@/api/iotInfo/IargeScreen";
import { StopLargeScreen } from "@/api/iotInfo/IargeScreen";

export default {
  data() {
    return {
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return "warning-row";
        } else if (rowIndex === 2) {
          return "success-row";
        }
        return "";
      },
      formLabelWidth: "120px",
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        localArea: "",
        connectionStatus: "",
      },
      countnum: 0,
      count: 0,
      tableData: [],
      multipleSelection: [],
      ids: {
        id: 0,
        equipmentNum: "",
        connectionStatus: true,
        lightPostNum: "",
        localArea: "",
        openingTime: "",
        closingTime: "",
      },
    };
  },
  created() {
    this.load();
    this.totalcount();
  },
  methods: {
    rowStyle() {
      return "text-align:center";
    },
    load() {
      ShowLargeScreen(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.load();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.load();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    shanchu(id) {
      if (!confirm("确认要删除吗")) {
        return;
      }

      this.ids.id = id;

      deleteLargeScreen(this.ids).then((res) => {
        if (res.data) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.load();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    tianjia() {
      this.$router.push("AddIargeScreen");
    },
    fantian(id) {
      this.$router.push({ path: "UpdateIargeScreen", query: { id: id } });
    },
    qidong(row) {
      StationLargeScreen(row).then((res) => {
        if (res.data) this.load();
      });
    },
    guanbi(row) {
      StopLargeScreen(row).then((res) => {
        if (res.data) this.load();
      });
    },
  },
};
</script>
<style>
.el-table .warning-row {
  background: rgb(230, 253, 253);
}

.el-table .success-row {
  background: #f4ebf9;
}
</style>